package com.jwaoo.chat.activity.presenter;

import android.app.Activity;

import com.dx.as.listener.IProInterface;
import com.jwaoo.chat.Message;
import com.jwaoo.chat.UserInfo;
import com.jwaoo.chat.activity.IP2PView;
import com.jwaoo.chat.activity.module.P2PModule;

import java.util.List;

/**
 * Created by jwaoo on 2017/8/2.
 */

public class P2PPresenter extends IProInterface{

    private P2PModule module;
    private IP2PView pView;
    private int requestCode = 1001; //
    public P2PPresenter(Activity activity, IP2PView pView) {
        super(activity);
        module = new P2PModule(activity.getApplicationContext(),this);
        this.pView = pView;
    }

    public void getContactInfo(int uuid){
        module.getContactInfo(uuid);
    }

    public void getSendFailedMessage(int uuid){
        module.getSendFailedMessage(requestCode,uuid);
    }

    @Override
    public void initialataData() {

    }

    @Override
    public void onResponse(Object response, int flg) {
        if (response != null) {
            if (requestCode == flg){
                List<Message> messageList = (List<Message>) response;
                pView.onSendFailedMessages(messageList);
            }else {
                UserInfo userInfo = (UserInfo) response;
                pView.getUserInfo(userInfo);
            }

        }
    }

    @Override
    public void onFailure(Throwable t) {
        super.onFailure(t);
    }
}
